home *** CD-ROM | disk | FTP | other *** search
- unit Dllform;
-
- interface
-
- uses WinTypes, WinProcs, Classes, Graphics, Forms, Controls,
- Buttons, SysUtils, StdCtrls,VBAPI;
-
- type
- TPasswordForm = class(TForm)
- Edit1: TEdit;
- Label1: TLabel;
- BitBtn2: TBitBtn;
- BitBtn1: TBitBtn;
- end;
-
- function GetPassword(Password: PChar): Integer; export;
- function RTrimStr(VBStrHLSTR: HLStr): HLStr; export;
- Function GetDirEntries(hlstrPath: HLSTR; hadDirInfoArray: HAD): Integer; export;
- function MinInt(X, Y: Integer): Integer; export;
- function MaxInt(X, Y: Integer): Integer; export;
-
-
- implementation
-
- uses Dialogs;
-
- {$R *.DFM}
-
-
- const
- VBTrue=-1;
- VBFalse=0;
-
-
- function GetPassword(Password: PChar): Integer;
- var
- PasswordForm: TPasswordForm;
- begin
- Result := VBFalse;
- PasswordForm := TPasswordForm.Create(Application);
- try
- with PasswordForm do
- if PasswordForm.ShowModal = mrOK then
- if UpperCase(Edit1.Text) <> UpperCase(StrPas(Password)) then
- MessageDlg('Invalid Password', mtWarning, [mbOK], 0)
- else
- Result := VBTrue;
- finally
- PasswordForm.Free;
- end;
- end;
-
-
- function RTrimStr(VBStrHLSTR: HLStr): HLStr;
- var
- i: Integer;
- TrimStr: PChar;
- VBStrLng: Word;
- strBuf: array[0..19]of char;
-
- begin
- TrimStr := VBDerefHlstrLen(VBStrHLSTR,VBStrLng);
- if VBStrLng>0 then
- begin
- for i := VBStrLng-1 downto 0 do begin
- if TrimStr[i] <> ' ' then begin
- TrimStr[i+1] := #0;
- RTrimStr := VBCreateTempHLSTR(TrimStr, i);
- Exit
- end;
- end;
- end
- else
- RTrimStr := VBStrHLSTR;
- End;
-
-
- Function GetDirEntries(hlstrPath: HLSTR; hadDirInfoArray: HAD): Integer;
-
- type
- tVBFileInfoRec=record
- Name: array[1..12] of char;
- Size: longint;
- Date: array[1..8] of char;
- Time: array[1..8] of char;
- end;
- tVBArray=array[1..(65520 div SizeOf(tVBFileInfoRec))] of tVBFileInfoRec;
-
- var
- SearchPath: String;
- FileInfoRec: TSearchRec;
- ArrayBounds: Longint;
- LowBound, HighBound: Integer;
- NoVBArrayIndexes: Integer;
- NoArrayElems: Integer;
- NoVBFileInfoElements: word;
- ErrorCd: Integer;
- FirstArrayElemPtr: Pointer;
- VBArray: ^tVBArray;
-
- Procedure AddElementToVBArray( var FileInfoRec: TSearchRec);
- var
- strDate: string[8];
- strTime: string[8];
- FileDateTime: TDateTime;
- VBFileInfoRec: tVBFileInfoRec;
-
- begin
- {Get the File Name}
- FillChar(VBFileInfoRec.Name, SizeOf(VBFileInfoRec.Name),' ');
- Move( FileInfoRec.Name[1], VBFileInfoRec.Name[1], Length(FileInfoRec.Name));
-
- {Get the File Size}
- VBFileInfoRec.Size := FileInfoRec.Size;
-
- {Get the Date}
- FileDateTime:= FileDateToDateTime(FileInfoRec.Time);
- strDate := FormatDateTime('dd\mm\yy', FileDateTime);
- strTime := FormatDateTime('HH:MM am/pm', FileDateTime);
- Move( strDate[1],VBFileInfoRec.Date, SizeOf(VBFileInfoRec.Date));
- Move( strTime[1],VBFileInfoRec.Time, SizeOf(VBFileInfoRec.Time));
-
- inc(NoVBFileInfoElements);
- VBArray^[NoVBFileInfoElements]:=VBFileInfoRec;
- end;
-
- begin
- {Initilize}
- NoVBFileInfoElements:= 0;
-
- {Get Path}
- SearchPath := StrPas(VBDerefZeroTermHlstr(hlstrPath));
-
- {Get No Array Elements}
- NoVBArrayIndexes:= VBArrayIndexCount(hadDirInfoArray); {This isn't used in this example dll}
- ArrayBounds:=VBArrayBounds(hadDirInfoArray,1);
- LowBound := LoWord(ArrayBounds);
- HighBound:=HiWord(ArrayBounds);
- NoArrayElems:= HighBound - LowBound + 1;
- {MessageDlg('NoArrayElems:'+ IntToStr(NoArrayElems), mtInformation, [mbOK], 0);}
-
- {Pointing the VBArray Address to the first element address in the passed VB Array}
- VBArray:= VBArrayFirstElem(hadDirInfoArray);
-
- {Read the Directory}
- ErrorCd:= FindFirst(SearchPath,(faAnyFile-faDirectory), FileInfoRec);
- While (ErrorCd=0) and (NoVBFileInfoElements < NoArrayElems) do begin
- AddElementToVBArray(FileInfoRec);
- ErrorCd:= FindNext(FileInfoRec);
- end; {While}
-
- {This MessageDlg can't happen because the above loop kicks out before finishing all selected files}
- If NoVBFileInfoElements > NoArrayElems then begin
- MessageDlg('No Files in selected TSearchRec > No VB Array size of:'+ IntToStr(NoArrayElems), mtWarning, [mbOK], 0);
- end;
- GetDirEntries:= NoVBFileInfoElements
-
- end;
-
-
- function MinInt(X, Y: Integer): Integer;
- begin
- if X < Y then MinInt := X else MinInt := Y;
- end;
-
- function MaxInt(X, Y: Integer): Integer;
- begin
- if X > Y then MaxInt := X else MaxInt := Y;
- end;
-
- end.
-